<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
    src="http://maps.googleapis.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(-19.26772, 146.78284);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
		
		
		$all_inputs = document.getElementsByTagName('input');
		
		
		var name_pat=/name=[^&]*/i;
		var lat_pat=/long=[^&]*/i;
		var long_pat=/lat=[^&]*/i;
		
		var i = 0;
		for (i ; i < $all_inputs.length; i++) {
		   if  ($all_inputs[i].className == 'station_data') {
				var value = $all_inputs[i].value;
				createMarker(map, new Number(new String(lat_pat.exec(value)).substring(5)), new Number(new String(long_pat.exec(value)).substring(4)), new String(name_pat.exec(value)).substring(5));	
			}
		}
		
		
		
  }
  
  function createMarker(map, lat, longitude, marker_title) {
	  var myLatlng = new google.maps.LatLng(longitude, lat);
		  
	  var marker = new google.maps.Marker({
		  position: myLatlng, 
		  map: map, 
		  title: marker_title
	  });   
  }

</script>
</head>
<body onload="initialize()">





<?php

$connection = mysql_connect('localhost', 'admin', 'admin');
mysql_query('USE aws;');
$result = mysql_query('SELECT * from `weatherstation`;');

if($result) {
	$names = array();
	
	$count = 0;
	
	echo "<form action='googlemap1.php' method='post'>";
		while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
			$names[] =  $row["aws_name"];
			$count++;
			echo "<input class='station_data' id='station_" . $count . "' type='hidden' value='id=".$row["aws_id"]."&name=".$row["aws_name"]."&lat=".$row["aws_latitude"]."&long=".$row["aws_longitude"]."' />";
		}	
		echo "<br />";

		echo "<select id='weather_stations' name='weather_stations'>";
		
			for($i = 0; $i<count(names); $i++) {
				echo "<option class='data_box' " . (isset($_POST['weather_stations']) &&  $_POST['weather_stations'] == $names[$i] ? "selected='selected'" : "") . " >" . $names[$i] . "</option>";
			}
		
		echo "</select>";		
		echo "<input type='submit' value='submit' />";
	echo "</form>";
	
	mysql_free_result($result);
} else {
	echo('Query failed');// error message
	
}


		
mysql_close($connection);
?>


<div id="map_canvas" style="width:100%; height:100%"></div>


<?php
if (isset($_POST['weather_stations'])) {
	echo $_POST['weather_stations'];
	
	echo "<fieldset>";
	echo "<legend>Test name</legend>";
	echo "<table>";
	
		echo "<tr>";			
			echo "<td></td>";
		echo "</tr>";
	echo "</table>";
	echo "</fieldset>";
	//------------do table------------
}
?>


</body>
</html>